package logic

import (
	"context"
	"vip_srv/vipsrvclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderPushLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderPushLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderPushLogic {
	return &OrderPushLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderPushLogic) OrderPush(req *types.OrderPushRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	if req.UserId <= 0 {
		return &types.Response{
			Code:    500,
			Message: "无效的账号数据",
			Data:    nil,
		}, nil
	}
	push, err := l.svcCtx.VipSrv.OrderPush(l.ctx, &vipsrvclient.OrderPushRequest{
		AskMonth: req.AskMonth,
		PayLand:  req.PayLand,
		UserId:   req.UserId,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "订单新建成功，请尽快支付",
		Data:    push,
	}, nil
}
